<?php
            $dir_unique_name = "KeyConversion".time();
            if(!is_dir("./upload/".$dir_unique_name)){   //this checks to make sure the directory does not already exist
            mkdir("./upload/".$dir_unique_name, 0777, true); //if the directory doesn't exist then make it
            chmod("./upload/".$dir_unique_name, 0777);  //chmod to 777 lets us write to the directory
            }
            $uploaddir='./upload/' . $dir_unique_name .'/';   //lets put the directory into a variable notice added slash on end 

            #echo "The upload dir is $uploaddir";
          if ($_FILES["file"]["error"] > 0)
            {
            #echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
            }
          else
            {
        #    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        #    echo "Type: " . $_FILES["file"]["type"] . "<br />";
        #    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        #    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

            if (file_exists($uploaddir . $_FILES["file"]["name"]))
              {
              #echo $_FILES["file"]["name"] . " already exists. ";
              }
            else
              {
              move_uploaded_file($_FILES["file"]["tmp_name"],
              $uploaddir . $_FILES["file"]["name"]);
              #echo "Stored in: " . $uploaddir . $_FILES["file"]["name"];
              }
            }
                $filename =  $_FILES["file"]["name"];
                #echo "\n This is filename = ".$filename;


                exec("./upload.cgi filename=$filename output=$uploaddir");

?>
